# -*- coding: utf-8 -*-
# @Time    : 2019/10/16 15:33
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : slice_object.py
import numbers


class Group:
    # 支持切片操作
    def __init__(self, group_name, company_name, staffs):
        self.group_name = group_name
        self.company_name = company_name
        self.staffs = staffs

    def __reversed__(self):
        """数据反转"""
        self.staffs.reverse()

    def __getitem__(self, item):
        """变为可切片的对象"""
        # return self.staffs[item]
        cls = type(self)  # 取到当前的类
        if isinstance(item, slice):
            return cls(group_name=self.group_name, company_name=self.company_name, staffs=self.staffs[item])
        elif isinstance(item, numbers.Integral):
            return cls(group_name=self.group_name, company_name=self.company_name, staffs=[self.staffs[item]])  # 变为数组

    def __len__(self):
        return len(self.staffs)

    def __iter__(self):
        return iter(self.staffs)

    def __contains__(self, item):
        """ if in 判断使用"""
        if item in self.staffs:
            return True
        else:
            return False


staffs = ["a1", "b1", "c1"]
group = Group(company_name="znufe", group_name="user", staffs=staffs)
sub_group = group[:2]
test_group = group[0]
print(len(group))
if "a1" in group:
    print("yes")
reversed(group)

